Skip to content

experiment: PEP810 test compute lazy loading#17594

Closed
hebaalazzeh wants to merge 2 commits into
mainfrom
test-compute-lazy-loading
Closed

experiment: PEP810 test compute lazy loading#17594
hebaalazzeh wants to merge 2 commits into
mainfrom
test-compute-lazy-loading

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

This PR is a proof-of-concept demonstrating the impact of native Python 3.15+ (PEP 810) lazy loading on a large generated GAPIC package (google-cloud-compute).

This PR applies the generator changes proposed in PR #17591 to the google-cloud-compute package. By utilizing the __lazy_modules__ dictionary, the package defers importing underlying service modules until they are explicitly accessed, significantly reducing the initial import footprint and startup time.

Note: This PR is currently for testing and review purposes to observe the generated diff and validate CI behavior. It depends on the generator changes in #17591

Changes Made

  • Regenerated google-cloud-compute using the updated gapic-generator templates.
  • Added __lazy_modules__ definition inside google/cloud/compute_v1/__init__.py wrapped in an if sys.version_info >= (3, 15): block.
  • Ran ruff format to ensure the generated dict aligns with CI formatting constraints.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for lazy-loading modules in Python 3.15+ by defining __lazy_modules__ in the package initialization templates and generated files. A critical issue was identified in the template where sys is used without being imported, which would lead to a NameError at runtime.


from importlib import metadata

if sys.version_info >= (3, 15):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The sys module is referenced here (sys.version_info) but it is not imported in this template. This will cause a NameError at runtime in the generated __init__.py files. Please import sys before using it.

import sys

if sys.version_info >= (3, 15):

@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini

@hebaalazzeh hebaalazzeh changed the title Phase 1: PEP810 test compute lazy loading experiment: PEP810 test compute lazy loading Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant